package cn.xy.demo04;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyInvocationHandler implements InvocationHandler{

    private Object object;

    public void setObject(Object object){
        this.object = object;
    }

    public Object getProxy() {
        return Proxy.newProxyInstance(this.getClass().getClassLoader(),object.getClass().getInterfaces(),this);
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        show(method.getName());
        Object result = method.invoke(object, args);
        return result;
    }

    public void show(String str){
        System.out.println("[INFO]:执行了"+str+"方法");
    }
}
